<script type="text/javascript">
    $(function() {
        $("#monto").numeric(".");
        
        ventana("habitaciones", 1200, 670, true, "center");
        $("#abrirHab").click(function() {
            $('#habitaciones').dialog('open');
        });
        $("#buscarDni").click(function() {
            var dni = $("#dni").val();
            if (dni !== "")
                buscarCliente("<?php echo base_url('intranet/reserva/clientesxDNI'); ?>/" + dni);
            else
                alert("Ingrese DNI a buscar.");
        });
        $("#resetear").click(function() {
            $('.control-group').removeClass('error');
            $('.control-group').removeClass('info');
            $('#cod').val("");
            $('.help-inline').remove();
        });
        $('#formficha').validate({
            errorElement: 'span',
            errorClass: 'help-inline',
            focusInvalid: false,
            rules: {
                hora: {
                    required: true
                },
                habi: {
                    required: true,
                    number: true
                },
                fecIng: {
                    required: true
                },
                nom: {
                    required: true,
                    minlength: 3,
                },
                dni: {
                    required: true,
                    minlength: 8,
                    number: true
                }
            },
            messages: {
                hora: {
                    required: "Debe ingresar una hora."
                },
                habi: {
                    required: "Debe seleccionar una habitación.",
                    number: "Se requiere número de habitación."
                },
                fecIng: {
                    required: "Debe seleccionar la fecha."
                },
                nom: {
                    required: "Ingrese nombre del cliente.",
                    minlength: "El nombre debe tener un minimo de 3 caracteres."
                },
                dni: {
                    required: "Ingrese dni del cliente a buscar.",
                    minlength: "Ingrese 8 dígitos.",
                    number: "Debe ingresar un dato numérico de 8 dígitos."
                }
            },
            highlight: function(e) {
                $(e).closest('.control-group').removeClass('info').addClass('error');
            },
            success: function(e) {
                $(e).closest('.control-group').removeClass('error').addClass('info');
                $(e).remove();
            },
            errorPlacement: function(error, element) {
                var controls = element.closest('.controls');
                controls.append(error);
                //error.insertAfter(element);
            }/*,
             submitHandler: function(form) {
             },
             invalidHandler: function(form) {
             }*/
        });
    });
</script>

<div class="page-content" style="background-color: #F8F8F8;">
    <div class="page-header position-relative">
        <h1>Ficha de Registro<small><i class="icon-double-angle-right"></i> Registrar</small></h1>
    </div>
    <div class="row-fluid">
        <div class="span12" >
            <form id="formficha" action="<?php echo base_url("intranet/reserva/Registrar"); ?>" class="form-horizontal" method='post'>
                <div class="row-fluid">
                    <div class="span6">
                        <div class="control-group">
                            <label class="control-label" for="hora"><span>Hora</span></label>
                            <div class="controls">
                                <div id="horaAuto" class="input-append bootstrap-timepicker">

                                </div>
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="habi">Hab. N°</label>
                            <div class="controls">
                                <input type='hidden' id='id_habi' name='id_habi'>
                                <input type='text' id='habi' class="span3" readonly="readonly" name='habi' title="Seleccione habitación">
                                <button type="button" id="abrirHab" class="blue btn btn-small btn-primary">
                                    <i class="icon-search"></i>
                                </button>
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="fecNac">Fecha Ingreso</label>
                            <div class="controls">
                                <div class="row-fluid input-append">
                                    <input class="span4 fecha" id='fecIng' name='fecIng' type="text" value="" readonly="readonly" />
                                    <span class="add-on">
                                        <i class="icon-calendar"></i>
                                    </span>
                                </div>
                            </div>                                            
                        </div>
                    </div>
                    <div class="span6">
                        <div class="space-26"></div>
                        <div class="control-group">
                            <label class="control-label" for="monto">Monto</label>
                            <div class="controls">
                            <div class="row-fluid input-prepend">
                                <span class="add-on">
                                    <i class="icon-dollar"></i>
                                </span>
                                <input class="span3" type="text" name="monto" id="monto" value="0.00" />
                            </div>
                                </div>
                        </div>
                    </div>
                </div>
                <div class="row-fluid">                    
                    <div class="span6">
                        <h3 class="header smaller lighter blue">Datos del Pasajero</h3>
                        <div class="control-group">
                            <label class="control-label" id="lblNombre" for="nom">Nombres y Apellidos</label>
                            <div class="controls">
                                <input type='hidden' id='cod' name='cod' value="" >
                                <input type='text' id='nom' name='nom' placeholder="Nombre completo" class="span10">
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="nrodoc">DNI</label>
                            <div class="controls">
                                <input type='text' id='dni' name='dni' placeholder="8 dígitos" class="span3" maxlength="8">
                                <button type="button" id="buscarDni" class="blue btn btn-small btn-primary" title="Buscar DNI">
                                    <i class="icon-search"></i>
                                </button>
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="ocupa">Ocupación</label>
                            <div class="controls">
                                <input type='text' id='ocupa' name='ocupa' class="span5" value="">
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="fecNac">Fecha Nacimiento</label>
                            <div class="controls">
                                <div class="row-fluid input-append">
                                    <input class="span4 fechaMY" id='fecNac' name='fecNac' type="text"  value="" readonly="readonly" />
                                    <span class="add-on">
                                        <i class="icon-calendar"></i>
                                    </span>
                                </div>
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="lugar">Lugar (Natural)</label>
                            <div class="controls">
                                <input type='text' id='lugar' name='lugar' value="">
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="procedencia">Lugar de Procedencia</label>
                            <div class="controls">
                                <input type='text' id='procedencia' name='procedencia' value="">
                            </div>                                            
                        </div>
                    </div>
                    <div class="span6">
                        <h3 class="header smaller lighter blue">Datos de la Empresa</h3>
                        <div class="control-group">
                            <label class="control-label" for="rzSocial">Razón Social</label>
                            <div class="controls">
                                <input type='text' id='rzSocial' name='rzSocial' class="span10" value="">
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="ruc">RUC</label>
                            <div class="controls">
                                <input type='text' id='ruc' class="span4" name='ruc' maxlength="11" placeholder="11 dígitos">
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="dir">Dirección</label>
                            <div class="controls">
                                <input type='text' id='dir' name='dir' class="span10" >
                            </div>                                            
                        </div>
                        <div class="control-group">
                            <label class="control-label" for="dir">Observación</label>
                            <div class="controls">
                                <textarea id="obs" name="obs" class="span10" placeholder="Ingrese comentario u observación" style="height: 130px" maxlength="200"></textarea>
                            </div>                                            
                        </div>
                    </div>
                </div>
                <div class="row-fluid">
                    <div class="span12">
                        <div class="form-actions">
                            <button id="registrar" class="btn btn-info" type="submit">
                                <i class="icon-ok bigger-110"></i>
                                Registrar
                            </button>

                            &nbsp; &nbsp; &nbsp;
                            <button class="btn" id="resetear" type="reset">
                                <i class="icon-undo bigger-110"></i>
                                Limpiar
                            </button>
                        </div>
                    </div>
                </div>
            </form>
        </div>
    </div>
</div>
<div id="habitaciones" title="TABLERO DE HABITACIONES">
    <div class="widget-body">
        <div class="widget-body-inner">
            <div class="widget-main">

                <div class="widget-header header-color-blue2">
                    <h5 class="bigger lighter"> <i class="icon-bell-alt"></i> Segundo Piso</h5>
                </div>
                <table style="width: 100%;"  >
                    <div class="widget-box pricing-box">
                        <tr>
                            <?php
                            for ($c = 0; $c < 11; $c++) {
                                ?>

                                <td  style="height: 100px; width: 9%;"> <button  onclick="cargardatosHab(<?php echo $registros[$c]->id_habi; ?>,<?php echo $registros[$c]->nro_habi; ?>)" <?php
                                    if (isset($registros3)) {
                                        if ($registros3 != NULL) {
                                            foreach ($registros3 as $fila1) {
                                                if ($c + 1 == $fila1->habitacion) {
                                                    if ($fila1->est_reg == 1) {
                                                        echo " disabled='true' class='btn btn-app btn-danger radius-4 '";
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    if (isset($registros2)) {
                                        if ($registros2 != NULL) {
                                            foreach ($registros2 as $fila1) {
                                                if ($c + 1 == $fila1->habitacion) {
                                                    if ($fila1->est_res == 1) {
                                                        echo " disabled='true' class='btn btn-app btn-warning radius-4 '";
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    ?>  class="btn btn-app"  type="button" style="height:95%; width: 95%; text-align: center; "><span style="font-size: 32px;"><?php echo $registros[$c]->nro_habi; ?></span></button></td>
                                                                             <?php } ?>
                        </tr>
                </table>
                <div class="widget-header header-color-blue2">
                    <h5 class="bigger lighter"><i class="icon-bell-alt"></i> Tercer Piso</h5>
                </div>
                <table style="width: 100%;"  >
                    <tr><?php
                        for ($j = 11; $j < 22; $j++) {
                            ?>

                            <td  style="height: 100px; width: 9%;"><button onclick="cargardatosHab(<?php echo $registros[$j]->id_habi; ?>,<?php echo $registros[$j]->nro_habi; ?>)"  <?php
                                if (isset($registros3)):
                                    if ($registros3 != NULL) {
                                        foreach ($registros3 as $fila1) {
                                            if ($j + 1 == $fila1->habitacion) {
                                                if ($fila1->est_reg == 1) {
                                                    echo " disabled='true' class='btn btn-app btn-danger radius-4 '";
                                                }
                                            }
                                        }
                                    }
                                endif;
                                if (isset($registros2)):
                                    if ($registros2 != NULL) {
                                        foreach ($registros2 as $fila1) {
                                            if ($j + 1 == $fila1->habitacion) {
                                                if ($fila1->est_res == 1) {
                                                    echo " disabled='true' class='btn btn-app btn-warning radius-4 '";
                                                }
                                            }
                                        }
                                    }
                                endif;
                                ?>  class="btn btn-app" style="height:95%; width: 95%; text-align: center; "><span style="font-size: 32px;"><?php echo $registros[$j]->nro_habi; ?></span></button></td>
                        <?php } ?>                                 </tr>
                </table>
                <div class="widget-header header-color-blue2">
                    <h5 class="bigger lighter"><i class="icon-bell-alt"></i> Primer Piso</h5>
                </div>
                <table style="width: 100%;"  >
                    <tr><?php for ($l = 22; $l < 26; $l++) { ?>
                            <td  style="height: 100px; width: 9%;"><button onclick="cargardatosHab(<?php echo $registros[$l]->id_habi; ?>,<?php echo $registros[$l]->nro_habi; ?>)" <?php
                                if (isset($registros3)):
                                    if ($registros3 != NULL) {
                                        foreach ($registros3 as $fila1) {
                                            if ($l + 1 == $fila1->habitacion) {
                                                if ($fila1->est_reg == 1) {
                                                    echo " disabled='true' class='btn btn-app btn-danger radius-4 '";
                                                }
                                            }
                                        }
                                    }
                                endif;
                                if (isset($registros2)):
                                    if ($registros2 != NULL) {
                                        foreach ($registros2 as $fila1) {
                                            if ($l + 1 == $fila1->habitacion) {
                                                if ($fila1->est_res == 1) {
                                                    echo " disabled='true' class='btn btn-app btn-warning radius-4 '";
                                                }
                                            }
                                        }
                                    }
                                endif;
                                ?> class="btn btn-app"  style="height:95%; width: 95%; text-align: center; "><span style="font-size: 32px;"><?php echo $registros[$l]->nro_habi; ?></span></button></td>
                                                                       <?php } ?>
                        <td colspan="5"></td>
                    </tr>
                </table>
                <div class="widget-box pricing-box">
                    <div class="widget-header header-color-blue2">
                        <h5 class="bigger lighter" style="text-align: right; padding: 5px;"><i class="icon-asterisk "></i> Leyenda</h5>
                    </div>
                    <div class="widget-body" style=" padding: 10px; text-align: right;">
                        <button class="btn btn-danger btn-small">
                            <i class="icon-group"></i>
                        </button> <span>OCUPADO</span>
                        <button class="btn btn-warning btn-small">
                            <i class="icon-group"></i>
                        </button> <span>RESERVADO</span>
                        <button class="btn  btn-small">
                            <i class="icon-group"></i>
                        </button> <span>DISPONIBLE</span>
                    </div>
                </div>
            </div>
        </div>
    </div>

</div>
<?php
if (isset($msj)) {
    echo "<script> alert('" . $msj . "'); </script>";
}
?>

<script type="text/javascript">
    function startTime() {
        var today = new Date();
        var h = today.getHours();
        var m = today.getMinutes();
        var s = today.getSeconds();
        var meridiano = " am";
        if (h > 12) {
            h -= 12;
            meridiano = " pm"
        }
        if (h < 10) {
            h = "0" + h
        }
        var m = checkTime(m);
        var s = checkTime(s);
        var horas = h + ":" + m + ":" + s + meridiano;
        $("#horaAuto").html("<input type='text' id='hora' name='hora' value='" + horas + "' class='input-small'>" +
                "<span class='add-on'>" +
                "<i class='icon-time'></i>" +
                "</span>");
        t = setTimeout('startTime()', 500);
    }

    function checkTime(i)
    {
        if (i < 10) {
            i = "0" + i;
        }
        return i;
    }
    $(window).load(function() {
        startTime();
    });
</script>
